<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String context = request.getContextPath(); %>
<html>
<head>
    <title>代办任务列表</title>
    <link rel="stylesheet" href="<%=context %>/Source/lib/layui/css/layui.css">
    <style>
        .layui-table, .layui-table-view{
            margin: 0;
        }
    </style>
</head>

<body style="padding: 0;overflow:hidden;">
<!-- 2018/5/13新增，对外提供服务时，由外部服务决定获取谁的流程和什么应用下的流程 -->
<input type="hidden" id="app" value="${appName}" />
<input type="hidden" id="executorName" value="${executorName}" />
<input type="hidden" id="userId" value="${userId}" />

<%-- 表格 --%>
<div id="grid">
    <div id="mainGrid" style="margin: -1px; min-width: 680px;"></div>
</div>
</body>
<script src="<%=context %>/gooflow/jquery.min.js"></script>
<script src="<%=context %>/microcore/commonjs/utility.js"></script>
<script src="<%=context %>/Source/lib/layui/layui.js"></script>
<script type="text/javascript">
    var path = '<%=context %>';
    var _path = path+"/flow/task";
    var _process = path+"/flow/process";


    <!-- 2018/5/13新增，对外提供服务时，由外部服务决定获取谁的流程和什么应用下的流程 -->
    var app = $('#app').val();
    app = app==''?'':'&appName='+app
    var userId = $('#userId').val();
    userId = userId==''?'':'&userId='+userId
    var executorName = $('#executorName').val();
    executorName = executorName==''?'':'&executorName='+executorName

    // 表格
    var table;
    var layer;
    layui.use(['table','layer'], function(){

        table = layui.table;
        layer = layui.layer;

        table.render({
            elem: '#mainGrid'
            , url: _path + "/getTask?rnd=" + Math.random() + app +userId //数据接口
            ,method:'post'
            // , page: true //开启分页
            , cols: [[ //表头
                // {field: 'id', title: 'id', align: 'center', sort: true}
                {field: 'startUser', title: '流程发起人', align: 'center', sort: true}
                , {field: 'processName', title: '业务名称', align: 'center', sort: true}
                , {field: 'flowRemark', title: '工作说明', align: 'center', sort: true}
                , {field: 'taskName', title: '节点名称', align: 'center', sort: true}
                , {title: '任务', align: 'center', sort: true, templet: function (item) {
                        var result = '';
                        result += " <a class=\"layui-btn layui-btn-sm \" href=\"javascript:void(0)\" onclick=\"f_do_task('"
                            + item.taskId + "','" + item.taskName + "','"
                            + item.editPageUrl + "','" + item.taskType
                            + "','" + item.instanceId + "','" + item.pageHeight + "','" + item.pageWeight + "')\">" + item.taskName + "</a>";
                        return result;
                    }
                }
                ,{title: '操作', align: 'center', templet: function (item) {
                        var result = "";
                        if(item.viewPageUrl){
                            result = "<a class=\"layui-btn layui-btn-sm \" href=\"javascript:void(0)\" onclick=\"f_view('" + item.viewPageUrl + "')\">显示单据</a>";
                        }
                        result += " <a class=\"layui-btn layui-btn-sm \" href=\"javascript:void(0)\" onclick=\"f_status('" + item.instanceId + "')\">流程状态</a>";
                        result += " <a class=\"layui-btn layui-btn-sm \" href=\"javascript:void(0)\" onclick=\"f_picture('" + item.instanceId + "')\">流程图</a>";
                        result += "<input id=\"taskType\" type=\"hidden\" name=\"country\" value=\""+item.taskType+"\" />"
                        return result;
                    }
                }
            ]]
            ,response: {
                statusCode: 200 //成功的状态码，默认：0
            }
        });
    });

    $(function () {
        $("#grid").height(document.documentElement.clientHeight - $(".toolbar").height());
    });

    // 任务
    function f_do_task(taskId, taskNodeCode, editPageUrl, taskType, instanceId, pageHeight, pageWeight) {

        var url;
        if (editPageUrl == null || editPageUrl == "" || editPageUrl== "undefined") {
            var title='';
            if (taskType == "examine") {
                url = _path + "/toExamine?taskId=" + taskId + "&taskNodeCode=" + taskNodeCode + "&otherTaskIds=" + $("#" + instanceId).val()  + "&approverId=" + $('#userId').val() +"&executorName" +$('#executorName').val();
                title = '审批任务'
            } else {
                url = _path + "/toComplete?taskId=" + taskId + "&taskNodeCode=" + taskNodeCode + "&otherTaskIds=" + $("#" + instanceId).val() + "&taskType=" + taskType  + "&approverId=" + $('#userId').val() +"&executorName" +$('#executorName').val();
                title = '普通任务'
            }

            layer.open({
                type: 2,
                title: title,
                shadeClose: true,
                shade: 0.8,
                area: ['70%', '500px'],
                content:url, //iframe的url
                btn: ['提交', '取消'],
                yes: function(index, layero){
                    var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                    iframeWin.complete(location);//调用子页面的方法，得到子页面返回的ids

                }
            });

        } else {
            url = editPageUrl;

            $.ligerDialog.open({
                title: '普通任务', width: pageWeight, height: pageHeight, allowClose: true, isResize: true, url: url,
                buttons: [
                    {
                        text: '提交', onclick: function (item, dialog) {
                            BAP.openWaitting();
                            $.ajax({

                                url: _path + "/completeTask?taskId=" + taskId
                                + "&taskNodeCode=" + taskNodeCode
                                + "&otherTaskIds=" + $("#" + instanceId).val() + "&approverId=" + userId,
                                type: "GET",
                                contentType: 'application/json;charset=utf-8', //设置请求头信息
                                dataType: "json",
                                data: null,
                                success: function (result) {
                                    location.reload(true);
                                }
                            });
                        }
                    },
                    {
                        text: '取消', onclick: function (item, dialog) {
                            dialog.close();
                        }
                    }
                ]
            });
        }
    }

    // 显示单据
    function f_view(viewPageUrl) {
        window.open(viewPageUrl);
    }

    // 流程状态
    function f_status(instanceId) {
        var url;
        url = _path + "/toTaskDealHistoryList?instanceId=" + instanceId;
        layer.open({
            type: 2,
            title: '处理历史',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '500px'],
            content:url//iframe的url
        });
    }

    function f_picture(instanceId) {
        window.open(_process + "/processViewBpmn?instanceId=" + instanceId);
    }
</script>
</html>
